package cn.test.springdata.service;

import cn.test.springdata.dao.UserDao;
import cn.test.springdata.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @auther hanchao
 * @date 2016/10/25 14:23
 */
@Service
@Transactional
public class UserService {
    @Autowired
    private UserDao dao;
    public void addUser(User user){
        dao.save(user);
    }

    @Transactional(rollbackFor = Exception.class)
    public void testTx(){
        User user = dao.findOne(34);
        dao.delete(user);
        throw new RuntimeException("test");
    }
}
